package org.sbbs.tool;

public class SingleEntityExporter
    extends SbbsExporter {
    private String templateType = "singleEntity";

    protected void generateCore() {

        // generate sample-data.xml
        configureExporter( "ssh/" + templateType + "/dao/sample-data.ftl", "src/test/resources/{class-name}-sample-data.xml" ).start();

        // DAO Test
        configureExporter( "ssh/" + templateType + "/dao/dao-test.ftl", "src/test/java/{basepkg-name}/dao/{class-name}DaoTest.java" ).start();

        // DAO Interfaces
        configureExporter( "ssh/" + templateType + "/dao/dao.ftl", "src/main/java/{basepkg-name}/dao/{class-name}Dao.java" ).start();

        String daoFramework = getProperties().getProperty( "daoframework" );

        // DAO Implementation
        configureExporter( "ssh/" + templateType + "/dao/" + daoFramework + "/dao-impl.ftl",
                           "src/main/java/{basepkg-name}/dao/" + daoFramework + "/{class-name}Dao" + getDaoFilename( daoFramework ) + ".java" ).start();

        // Manager Test
        configureExporter( "ssh/" + templateType + "/service/manager-test.ftl",
                           "src/test/java/{basepkg-name}/service/impl/{class-name}ManagerImplTest.java" ).start();

        // Manager Interface
        configureExporter( "ssh/" + templateType + "/service/manager.ftl", "src/main/java/{basepkg-name}/service/{class-name}Manager.java" ).start();

        // Manager Implementation
        configureExporter( "ssh/" + templateType + "/service/manager-impl.ftl",
                           "src/main/java/{basepkg-name}/service/impl/{class-name}ManagerImpl.java" ).start();
    }

    protected void generateWeb() {
        String packaging = getProperties().getProperty( "packaging" );
        boolean webProject = packaging != null && packaging.equalsIgnoreCase( "war" );

        if ( !webProject )
            return;

        String webFramework = getProperties().getProperty( "webframework" );
        String fType = getProperties().getProperty( "fType" );
        String pojoName = System.getProperty( "entity" );
        String detailFullPathName = getProperties().getProperty( "detailFullPathName" );

        // tests
        configureExporter( "ssh/" + templateType + "/web/struts/action-test.ftl",
                           "src/test/java/{basepkg-name}/webapp/action/{class-name}ActionTest.java" ).start();

        // controllers
        configureExporter( "ssh/" + templateType + "/web/struts/action.ftl",
                           "src/main/java/{basepkg-name}/webapp/action/{class-name}PagedAction.java" ).start();
        // configureExporter( "ssh/"+templateType +"/web/struts/edit-action.ftl",
        // "src/main/java/{basepkg-name}/webapp/action/{class-name}EditAction.java" ).start();
        // views
        if ( fType.equals( "2" ) && pojoName.equals( detailFullPathName ) ) {
            configureExporter( "ssh/" + templateType + "/web/struts/detailList-view.ftl", "src/main/webapp/WEB-INF/pages/{class-name}List.jsp" ).start();
        }
        else {
            configureExporter( "ssh/" + templateType + "/web/struts/list-view.ftl", "src/main/webapp/WEB-INF/pages/{class-name}List.jsp" ).start();
        }

        configureExporter( "ssh/" + templateType + "/web/struts/form-view.ftl", "src/main/webapp/WEB-INF/pages/{class-name}Form.jsp" ).start();

        configureExporter( "ssh/" + templateType + "/web/struts/struts.ftl", "src/main/java/{basepkg-name}/webapp/struts_action_{class-name}.xml" ).start();

        // menu
        /*
         * configureExporter("ssh/"+templateType +"/web/menu.ftl",
         * "src/main/webapp/common/{class-name}-menu.jsp").start(); configureExporter("ssh/"+templateType
         * +"/web/menu-light.ftl", "src/main/webapp/common/{class-name}-menu-light.jsp").start();
         * configureExporter("ssh/"+templateType +"/web/menu-config.ftl",
         * "src/main/webapp/WEB-INF/{class-name}-menu-config.xml").start();
         */

        // i18n
        configureExporter( "ssh/" + templateType + "/web/ApplicationResources.ftl",
                           "src/main/java/{basepkg-name}/webapp/{class-name}-package.properties" ).start();

    }
}
